package Java实训.第七天字符流;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Task6 {
    /*
      定义一个 csv 文件内容如下：
      StuNO,StuName,age
      1001,zs,11
      1002,ll,22
      1003,ww,33
      以 csv 文件内容作为输入源，存入集合进行增删改查业务处理---查询 1003 学生对应信息
      */
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        List<Student> list = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\task6.csv"));
        String str = br.readLine();
        while ((str = br.readLine()) != null){
            list.add(new Student(str.split(",")[0], str.split(",")[1], Integer.parseInt(str.split(",")[2])));
        }
        while (true){
            System.out.println("请输入您要进行的操作");
            System.out.println("1:          查询");
            System.out.println("0:          退出");
            int a = sc.nextInt();
            if (a == 0){
                break;
            }else{
                System.out.println("请输入您要查询的学号:");
                String str1 = sc.next();
                int count = 0;
                for (Student student : list) {
                    if (str1.equals(student.getStuNO())){
                        count++;
                        System.out.println("学号: " + student.getStuNO());
                        System.out.println("姓名: " + student.getStuName());
                        System.out.println("年龄: " + student.getAge());
                    }
                }
                if (count == 0){
                    System.out.println("您输入的学号不存在，请重新输入");
                    continue;
                }
            }
        }
    }
}
class Student{
    private String stuNO;
    private String stuName;
    private Integer age;

    public Student(String stuNO, String stuName, Integer age) {
        this.stuNO = stuNO;
        this.stuName = stuName;
        this.age = age;
    }

    public String getStuNO() {
        return stuNO;
    }

    public void setStuNO(String stuNO) {
        this.stuNO = stuNO;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuNO='" + stuNO + '\'' +
                ", stuName='" + stuName + '\'' +
                ", age=" + age +
                '}';
    }
}
